package acwing;

import java.io.*;
import java.util.*;

public class ac03 {
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    static BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));
    static final int N = 1010;
    static int n, m;
    static int[] w = new int[N], v = new int[N];
    static int[] f = new int[N];
    static int cin() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static void main(String[] args) throws IOException {
        n = cin(); m = cin();
        for (int i = 1; i <= n; i ++ ) {
            v[i] = cin();
            w[i] = cin();
        }
        for (int i = 1; i <= n; i ++ ) {
            for (int j = v[i]; j <= m; j ++ ) {
                f[j] = Math.max(f[j], f[j - v[i]] + w[i]);
            }
        }
        out.println(f[m]);
        out.close();
    }
}